import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

class MtCenter extends StatefulWidget {
  const MtCenter({super.key});

  @override
  _MtCenterState createState() => _MtCenterState();
}

class _MtCenterState extends State<MtCenter> {
  List _foods = [];
  int activeIndex = 0;
  @override
  void initState() {
    super.initState();
    getFoodData();
  }

  getFoodData() async {
    Dio dio = Dio();
    var res =
        await dio.get("https://zhousg.atomgit.net/harmonyos5/takeaway.json");
    setState(() {
      _foods = res.data as List; // 数据更新
    });
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.bottomCenter,
      children: [_center(), _bottom()],
    );
  }

  //底部
  _bottom() {
    return Positioned(
        child: Container(
      width: double.infinity,
      height: 50,
      margin: const EdgeInsets.symmetric(horizontal: 20),
      padding: const EdgeInsets.symmetric(horizontal: 20),
      decoration: const BoxDecoration(
          color: Colors.black87,
          borderRadius: BorderRadius.all(Radius.circular(25))),
      child: const Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('￥0.00',
                  style: TextStyle(
                      fontSize: 18,
                      fontWeight: FontWeight.bold,
                      color: Colors.white)),
              Text(
                '预估另需配送费￥0.00元',
                style: TextStyle(color: Colors.white, fontSize: 12),
              ),
            ],
          ),
          Text('去下单', style: TextStyle(color: Colors.red)),
        ],
      ),
    ));
  }

  //中心区域
  _center() {
    return Container(
      width: double.infinity,
      height: double.infinity,
      decoration: const BoxDecoration(color: Colors.white),
      child: Row(
        children: [
          //左侧分类
          Container(
            width: 110,
            height: double.infinity,
            decoration: const BoxDecoration(color: Colors.black12),
            child: Column(
              children: [_centerLeft()],
            ),
          ),
          //右侧美食
          Expanded(flex: 1, child: _centerRight())
        ],
      ),
    );
  }

  //左侧分类
  _centerLeft() {
    return Container();
  }

  //右侧美食
  _centerRight() {
    return Container();
  }
}
